package org.easyx.core.ui.easyui;

import java.io.Serializable;
import java.util.List;

import org.easyx.core.utils.ObjKit;

/**
 * 分页工具类
 */
public class PageBean<T> implements Serializable{
	private static final long serialVersionUID = -7032126736611167516L;
	/**
     * 默认每页记录数(15).
     */
	private final static int PAGESIZE = 15 ; 
	
	
	private int status = 0;
	private String msg = "";
	
	private Integer pageNo;		// 当前页
    private Integer pageSize; 	// 每页显示多少条
    private String orderField;	 //查询排序的字段
    private String orderDirection;	//排序方式：升序降序
    
    private Integer total; 		// 总记录数
    private List<T> rows; 		//显示的记录列表，jqery easyui名称必须是rows 
    
	public PageBean(){
		this.pageNo = 1;
		this.pageSize = PAGESIZE;
	}
    public PageBean(int pageNo, int pageSize) {
        //计算当前页  
        if (pageNo <= 0) {
            this.pageNo = 1;
        } else {
            this.pageNo = pageNo;
        }
        //记录每页显示的记录数  
        if (pageSize < 0) {
            this.pageSize = PAGESIZE;
        } else {
            this.pageSize = pageSize;
        }
    }
    public PageBean(int pageNo, int pageSize, String orderField, String orderDirection) {
    	this(pageNo,pageSize);
    	
        // 排序字段，正序还是反序
    	if(ObjKit.isNotEmpty(orderField)){
    		this.orderField = orderField; // 排序字段
    	}
    	if(ObjKit.isNotEmpty(orderDirection)){
    		this.orderDirection = orderDirection;// asc，desc 
    	}
    }
    public PageBean(PageParam pageParam) {
    	this(pageParam.getPage(),pageParam.getRows(),pageParam.getSort(),pageParam.getOrder());
    }
    
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public Integer getPageNo() {
		return pageNo;
	}
	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}
	public Integer getPageSize() {
		return pageSize;
	}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	public Integer getTotal() {
		return total;
	}
	public void setTotal(Integer total) {
		this.total = total;
	}
	public List<T> getRows() {
		return rows;
	}
	public void setRows(List<T> rows) {
		this.rows = rows;
	}
	public String getOrderField() {
		return orderField;
	}
	public void setOrderField(String orderField) {
		this.orderField = orderField;
	}
	public String getOrderDirection() {
		return orderDirection;
	}
	public void setOrderDirection(String orderDirection) {
		this.orderDirection = orderDirection;
	}
}
